home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / html.h.z / html.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  37.8 KB  |  1,381 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Martin Jones (mjones@kde.org)
  3.               (C) 1997 Torben Weis (weis@kde.org)
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.     Boston, MA 02111-1307, USA.
  19. */
  20. //----------------------------------------------------------------------------
  21. //
  22. // KDE HTML Widget
  23.  
  24. #ifndef HTML_H
  25. #define HTML_H
  26.  
  27. #define KHTMLW_VERSION  1213        // 00.12.13
  28.  
  29. #include <qpainter.h>
  30. #include <qstrlist.h>
  31. #include <qpixmap.h>
  32. #include <qstack.h>
  33. #include <qfont.h>
  34. #include <qtimer.h>
  35. #include <qlist.h>
  36. #include <kurl.h>
  37.  
  38. class KHTMLWidget;
  39.  
  40.  
  41. #include "drag.h"
  42. #include "htmldata.h"
  43. #include "htmlobj.h"
  44. #include "htmlclue.h"
  45. #include "htmlform.h"
  46. #include "htmltoken.h"
  47. #include "htmlframe.h"
  48. #include "htmlview.h"
  49. #include "jscript.h"
  50.  
  51. // Default borders between widgets frame and displayed text
  52. #define LEFT_BORDER 10
  53. #define RIGHT_BORDER 20
  54. #define TOP_BORDER 10
  55. #define BOTTOM_BORDER 10
  56.  
  57.  
  58. //#define TORBENSDEBUG
  59. //#define MARTINSDEBUG
  60.  
  61. class KCharsetConverter;
  62.  
  63. void debugT( const char *msg , ...);
  64. void debugM( const char *msg , ...);
  65.  
  66. typedef void (KHTMLWidget::*parseFunc)(HTMLClueV *_clue, const char *str);
  67.  
  68. /**
  69.  * @short Basic HTML Widget.  Does not handle scrollbars or frames.
  70.  *
  71.  * This widget is good for use in your custom application which does not
  72.  * necessarily want to handle frames, or want custom control of scrollbars.
  73.  * To add content to the widget you should do the follwing:
  74.  * <PRE>
  75.  * view->begin( "file:/tmp/test.html" );
  76.  * view->parse();
  77.  * view->write( "<HTML><TITLE>...." );
  78.  * .....
  79.  * view->end();
  80.  * view->show();
  81.  * </PRE>
  82.  * The widget will take care of resize events and paint events.
  83.  * Have a look at the set of signals emitted by this widget. You should connect
  84.  * to most of them.
  85.  *
  86.  * Note: All HTML is parsed in the background using Qt timers, so you will not
  87.  * see any content displayed until the event loop is running.
  88.  */
  89. class KHTMLWidget : public KDNDWidget
  90. {
  91.     Q_OBJECT
  92. public:
  93.     /**
  94.      * Create a new HTML widget.  The widget is empty by default.
  95.      * You must use @ref #begin, @ref #write, @ref #end and @ref #parse
  96.      * to fill the widget with content.
  97.      *
  98.      * @param _name is the name of the widget. Usually this name is only
  99.      *              meaningful for Qt but in this case it is the name of
  100.      *              the HTML window. This means you can reference this name
  101.      *              in the < href=... target=... > tag. If this argument
  102.      *              is 0L then a unique default name is chosen.
  103.      *
  104.      * Note: pixdir should not be used - it is provided only for backward
  105.      * compatability and has no effect.
  106.      */
  107.     KHTMLWidget( QWidget *parent = 0L, const char *name = 0L,
  108.         const char *pixdir = 0L );
  109.     virtual ~KHTMLWidget();
  110.  
  111.     /**
  112.      * Clears the widget and prepares it for new content. If you display
  113.      * for example "file:/tmp/test.html", you can use the following code
  114.      * to get a value for '_url':
  115.      * <PRE>
  116.      * KURL u( "file:/tmp/test.html" );
  117.      * view->begin( u.directoryURL() );
  118.      * </PRE>
  119.      *
  120.      * @param _url is the url of the document to be displayed.  Even if you
  121.      * are generating the HTML on the fly, it may be useful to specify
  122.      * a directory so that any pixmaps are found.
  123.      * @param _dx is the initial horizontal scrollbar value. Usually you don't
  124.      * want to use this.
  125.      * @param _dy is the initial vertical scrollbar value. Usually you don't
  126.      * want to use this.
  127.      */
  128.     void begin( const char *_url = 0L, int _x_offset = 0, int _y_offset = 0 );
  129.  
  130.     /**
  131.      * Writes another part of the HTML code to the widget. You may call
  132.      * this function many times in sequence. But remember: The less calls
  133.      * the faster the widget is.
  134.      */
  135.     void write( const char * );
  136.  
  137.     /**
  138.      * Call this after your last call to @ref #write.
  139.      */
  140.     void end();
  141.  
  142.     /**
  143.      * Begin parsing any HTML that has been written using the @ref #write
  144.      * method.
  145.      *
  146.      * You may call this function immediately after calling @ref #begin. 
  147.      * In this case the HTML will be passed and displayed whenever the
  148.      * event loop is active.  This allows background parsing and display
  149.      * of the HTML as it arrives.
  150.      */
  151.     void parse();
  152.  
  153.     /**
  154.      * Stop parsing the HTML immediately.
  155.      */
  156.     void stopParser();
  157.  
  158.     /**
  159.      * Print current HTML page to the printer.
  160.      */
  161.     void print();
  162.  
  163.     /**
  164.      * Recalculate the size and position of objects in the page.
  165.      * This is mainly intended for internal use.
  166.      */
  167.     void calcSize();
  168.  
  169.     /**
  170.      * Selects all objects which refer to _url. All selected ojects
  171.      * are redrawn if they changed their selection mode.
  172.      */
  173.     virtual void selectByURL( QPainter *_painter, const char *_url, bool _select );
  174.     /**
  175.      * Selects/Unselects all objects with an associated URL.
  176.      * This is usually used to disable
  177.      * a selection. All objects are redrawn afterwards if they changed
  178.      * their selection mode.
  179.      */
  180.     virtual void select( QPainter *_painter, bool _select );
  181.  
  182.     /**
  183.      * Selects all objects with an associated URL in this rectangle and
  184.      * deselects all objects outside the rectangle. 
  185.      *
  186.      * @param _rect is a rectangle in display coordinates. This means
  187.      *              that the point (0,0) is the upper/left most point of
  188.      *              the widget but must not be this one for the HTML page.
  189.      *              This happens if the widget is being scrolled.
  190.      */
  191.     virtual void select( QPainter * _painter, QRect &_rect );
  192.  
  193.     /**
  194.      * Select all objects with a URL matching the regular expression.
  195.      *
  196.      * If _painter is null a new painter is created.
  197.      */
  198.     virtual void select( QPainter *_painter, QRegExp& _pattern, bool _select );
  199.  
  200.     /**
  201.      * Gets a list of all selected URLs. The list may be Null.
  202.      * You can test this using list.isNull().
  203.      */
  204.     virtual void getSelected( QStrList &_list );
  205.  
  206.     /**
  207.      * Selects all text between ( _x1, _y1 ) and ( _x2, y2 ).  The selection
  208.      * area selects text line by line, NOT by bounding rectangle.
  209.      */
  210.     virtual void selectText( QPainter *_painter, int _x1, int _y1,
  211.         int _x2, int _y2 );
  212.  
  213.     /**
  214.      * Get the text the user has marked.
  215.      *
  216.      * @param _str is the QString which will contain the text the user
  217.      * selected.  The selected text is appended to any text currently in
  218.      * _str.
  219.      */
  220.     virtual void getSelectedText( QString &_str );
  221.  
  222.     /**
  223.      * Has the user selected any text?  Call @ref #getSelectedText to
  224.      * retrieve the selected text.
  225.      *
  226.      * @return true if there is text selected.
  227.      */
  228.     bool isTextSelected() const
  229.     {    return bIsTextSelected; } 
  230.  
  231.     /**
  232.      * Checks out whether there is a URL under the point and returns a pointer
  233.      * to this URL or 0L if there is none.
  234.      *
  235.      * @param _point the point to test for the presence of a URL.  The
  236.      * point is relative to this widget.
  237.      */
  238.     const char* getURL( QPoint &_point );
  239.  
  240.     /**
  241.      * @return the width of the parsed HTML code. Remember that
  242.      * the documents width depends on the width of the widget.
  243.      */
  244.     int docWidth() const;
  245.  
  246.     /**
  247.      * @return the height of the parsed HTML code. Remember that
  248.      * the documents height depends on the width of the widget.
  249.      */
  250.     int docHeight() const;
  251.  
  252.     /**
  253.      * @return the url of this document
  254.      */
  255.     KURL &getDocumentURL()
  256.         {    return actualURL; }
  257.  
  258.     /**
  259.      * @return the base URL of this document
  260.      */
  261.     KURL &getBaseURL()
  262.         {    return baseURL; }
  263.  
  264.     /**
  265.      * @return the horizontal position the view has been scrolled to.
  266.      */
  267.     int xOffset() const { return x_offset; }
  268.  
  269.     /**
  270.      * @return the vertical position the view has been scrolled to.
  271.      */
  272.     int yOffset() const { return y_offset; }
  273.  
  274.     /**
  275.      * Find the anchor named '_name'. If the anchor is found, the widget
  276.      * scrolls to the closest position. Returns TRUE if the anchor has
  277.      * been found.
  278.      */
  279.     bool gotoAnchor( const char *_name );
  280.  
  281.     /**
  282.      * Causes the widget contents to scroll automatically.  Call
  283.      * @ref #stopAutoScrollY to stop.  Stops automatically when the
  284.      * top or bottom of the document is reached.
  285.      * 
  286.      * @param _delay Time in milliseconds to wait before scrolling the
  287.      * document again.
  288.      * @param _dy The amount to scroll the document when _delay elapses.
  289.      */
  290.     void autoScrollY( int _delay, int _dy );
  291.  
  292.     /**
  293.      * Stops the document from @ref #autoScrollY ing.
  294.      */
  295.     void stopAutoScrollY();
  296.  
  297.     /**
  298.      * Returns if the widget is currently auto scrolling.
  299.      */
  300.     bool isAutoScrollingY()
  301.          {    return autoScrollYTimer.isActive(); }
  302.  
  303.     /**
  304.      * If this widget belongs to a @ref HTMLView, then this function
  305.      * is used to tell the widget about its owner.
  306.      *
  307.      * @see #htmlView     
  308.      * @see #getView
  309.      */
  310.     void setView( KHTMLView *_view ) { htmlView = _view; }
  311.  
  312.     /**
  313.      * @return the @ref KHTMLView this widget belongs to.
  314.      *
  315.      * @see #setView
  316.      */
  317.     KHTMLView* getView() { return htmlView; }
  318.  
  319.     /**
  320.      * @return TRUE if the currently displayed document is a frame set.
  321.      */
  322.     bool isFrameSet() { return bIsFrameSet; }
  323.  
  324.     /**
  325.      * Tells this widget that it displays a frameset.
  326.      * For internal use only.
  327.      */
  328.     void setIsFrameSet( bool _b );
  329.  
  330.     /**
  331.      * @return a pointer to the currently selected frame ( @ref KHTMLView ) if
  332.      * we are displaying a frameset, otherwise 0L. If this widget is the
  333.      * selected one then @ref htmlView is returned. Otherwise all
  334.      * @ref HTMLFrameSet instances are asked.
  335.      */
  336.     KHTMLView* getSelectedFrame();
  337.   
  338.     /**
  339.      * @return TRUE if the currently displayed document is a frame.
  340.      */
  341.     bool isFrame() { return bIsFrame; }
  342.  
  343.     /**
  344.      * Tell the widget wether it is a frame or not.
  345.      * For internal use only.
  346.      *
  347.      * @see #isFrame
  348.      */
  349.     void setIsFrame( bool _frame);
  350.  
  351.     /**
  352.      * Sets the margin width in pixels. This function is used to implement the
  353.      * <tt><frame marginwidth=... ></tt> tag.
  354.      * It is called from @ref KHTMLView and is for INTERNAL USE ONLY.
  355.      *
  356.      * @see #leftBorder
  357.      * @see #rightBorder
  358.      * @see KHTMLView::setMarginWidth
  359.      */
  360.     void setMarginWidth( int _w ) { leftBorder = _w; rightBorder = _w + 4; }
  361.  
  362.     /**
  363.      * Sets the margin height in pixels. This function is used
  364.      * to implement the
  365.      * <tt><frame marginheight=... ></tt> tag.
  366.      * It is called from @ref KHTMLView and is for INTERNAL USE ONLY.
  367.      *
  368.      * @see #topBorder
  369.      * @see #bottomBorder
  370.      * @see KHTMLView::setMarginHeight
  371.      */
  372.     void setMarginHeight( int _h ) { topBorder = _h; bottomBorder = _h; }
  373.   
  374.     /**
  375.      * @return if the user selected this widget.
  376.      *
  377.      * @see #bIsSelected
  378.      * @see #setSelected
  379.      */
  380.     bool isSelected()
  381.     {
  382.       return bIsSelected;
  383.     }
  384.   
  385.     /**
  386.      * Switches the 'selected state' of this widget. This results in the
  387.      * drawing or deleting of the black border around the widget.
  388.      *
  389.      * @see #isSelected
  390.      */
  391.     void setSelected( bool _active );
  392.   
  393.     /**
  394.      * Sets the base font size ( range: 2-5,  default: 3 ).
  395.      *
  396.      * Note that font sizes are not defined in points.
  397.      * Font sizes range from 1 (smallest) to 7 (biggest).
  398.      */
  399.     void setDefaultFontBase( int size )
  400.     {    if ( size < 2 ) size = 2;
  401.         else if ( size > 5 ) size = 5;
  402.         defaultSettings->fontBaseSize = size - 1;
  403.     }
  404.  
  405.     /**
  406.      * Sets the standard font style.
  407.      *
  408.      * @param name is the font name to use for standard text.
  409.      */
  410.     void setStandardFont( const char *name )
  411.     {    defaultSettings->fontBaseFace = name; }
  412.  
  413.     /**
  414.      * Sets the fixed font style.
  415.      *
  416.      * @param name is the font name to use for fixed text, e.g.
  417.      * the <tt><pre></tt> tag.
  418.      */
  419.     void setFixedFont( const char *name )
  420.     {    defaultSettings->fixedFontFace = name; }
  421.  
  422.     /**
  423.      * Sets the default background color to use when one isn't specified
  424.      * explicitly by <tt><body bgcolor=...></tt>
  425.      */
  426.     void setDefaultBGColor( const QColor &col )
  427.     {    defaultSettings->bgColor = col; }
  428.  
  429.     /**
  430.      * Sets the default text colors.
  431.      */
  432.     void setDefaultTextColors( const QColor &normal, const QColor &link,
  433.     const QColor &vlink )
  434.     {
  435.     defaultSettings->fontBaseColor = normal;
  436.     defaultSettings->linkColor = link;
  437.     defaultSettings->vLinkColor = vlink;
  438.     }
  439.  
  440.     /**
  441.      * Set whether links are drawn in underlined text.
  442.      */
  443.     void setUnderlineLinks( bool ul )
  444.     { defaultSettings->underlineLinks = ul; }
  445.  
  446.     /**
  447.      * Sets the cursor to use when the cursor is on a link.
  448.      */
  449.     void setURLCursor( const QCursor &c )
  450.     {    linkCursor = c; }
  451.  
  452.     /**
  453.      * Cryptic?  This is used to set the number of tokens to parse
  454.      * in one timeslice during background processing.
  455.      *
  456.      * You probably don't need to touch this.
  457.      */
  458.     void setGranularity( int g )
  459.     {   granularity = g; }
  460.  
  461.     /*
  462.      * If a HTMLObject object needs a file from the web, it
  463.      * calls this function.
  464.      */
  465.     void requestFile( HTMLObject *_obj, const char *_url );
  466.  
  467.     /*
  468.      * Cancels a previous @ref requestFile.
  469.      */
  470.     void cancelRequestFile( HTMLObject *_obj );
  471.  
  472.     /*
  473.      * Cancels all @ref requestFile.
  474.      */
  475.     void cancelAllRequests();
  476.  
  477.     // This function is called to download the background image from the web
  478.     void requestBackgroundImage( const char *_url );
  479.  
  480.     /*
  481.      * This function is used to repaint images that have been loaded from the
  482.      * web.
  483.      */
  484.     void paintSingleObject( HTMLObject *_obj );
  485.  
  486.     /*
  487.      * Schedule a paint event.  This is used internally to force a paint
  488.      * event when, for example, an image has been loaded and the document
  489.      * has been layed out again.
  490.      */
  491.     void scheduleUpdate( bool clear );
  492.  
  493.     /**
  494.      * Internal use - calculates the absolute position of the objects.
  495.      */
  496.     void calcAbsolutePos();
  497.  
  498.     /*
  499.      * return the map matching mapurl
  500.      * For internal use only
  501.      */
  502.     HTMLMap *getMap( const char *mapurl );
  503.  
  504.     // Registers QImageIO handlers for JPEG and GIF
  505.     static void registerFormats();
  506.  
  507.     /**
  508.      * @return a pointer to the @ref JSEnvironment instance used by this widget.
  509.      *         Every call to this function will result in the same pointer.
  510.      *
  511.      * @see #jsEnvironment
  512.      */
  513.     JSEnvironment* getJSEnvironment();
  514.  
  515.     /**
  516.      * A convenience function to access the @ref JSWindowObject of this html
  517.      * widget.
  518.      *
  519.      * @see #getJSEvironment
  520.      */
  521.     JSWindowObject* getJSWindowObject();
  522.  
  523.     /**
  524.      * @return a list of all frames.
  525.      *
  526.      * @see #frameList
  527.      */
  528.     QList<KHTMLWidget>* getFrameList() { return &frameList; }
  529.     
  530.      /**
  531.      * Set document charset. 
  532.      *
  533.      * Any <META ...> setting charsets overrides this setting
  534.      *
  535.      * @return TRUE if successfull
  536.      *
  537.      */
  538.     bool setCharset(const char *name); 
  539.  
  540.     //-----------------------------------------------------------
  541.     // FUNCTIONS used for KFM Extension
  542.     // -----------------------------------------------------------
  543.     bool cellDown();
  544.     bool cellUp();
  545.     bool cellLeft();
  546.     bool cellRight();
  547.     void cellSelected();
  548.     void cellActivated();
  549.     void cellContextMenu();
  550.     //-----------------------------------------------------------
  551.     // End KFM Extensions
  552.     // -----------------------------------------------------------
  553.   
  554. signals:
  555.     /**
  556.      * This signal is emitted whenever the Widget wants to
  557.      * change the window's title. Usually this is the text
  558.      * enclosed in <tt><title>....</title></tt>.
  559.      */
  560.     void setTitle( const char * );
  561.  
  562.     /**
  563.      * The user pressed ALT + Up
  564.      */
  565.     void goUp();
  566.     /**
  567.      * The user pressed ALT + Left
  568.      */
  569.     void goLeft();
  570.     /**
  571.      * The user pressed ALT + Right
  572.      */
  573.     void goRight();
  574.   
  575.     /**
  576.      * The user double clicked on a URL.
  577.      *
  578.      * @param _url the URL that the user clicked on.
  579.      * @param _button the mouse button that was used.
  580.      */
  581.     void doubleClick( const char * _url, int _button);
  582.  
  583.     /**
  584.      * Tells the parent, that the widget has scrolled. This may happen if
  585.      * the user selects an <tt><a href="#anchor"></tt>.
  586.      */
  587.     void scrollVert( int _y );
  588.  
  589.     /**
  590.      * Tells the parent, that the widget has scrolled. This may happen if
  591.      * the user selects an <a href="#anchor">.
  592.      */
  593.     void scrollHorz( int _x );
  594.  
  595.     /**
  596.      * Signals that a URL has been selected using a single click.
  597.      *
  598.      * @param _url is the URL clicked on.
  599.      * @param _button is the mouse button clicked.
  600.      */
  601.     void URLSelected( const char *_url, int _button );
  602.  
  603.     /**
  604.      * Signals that a URL has been selected using a single click.
  605.      *
  606.      * @param _url is the URL clicked on.
  607.      * @param _button is the mouse button clicked.
  608.      * @param _target is the target window or 0L if there is none.
  609.      * ( Used to implement frames ).
  610.      */
  611.     void URLSelected( const char *_url, int _button, const char *_target );
  612.  
  613.     /**
  614.      * Signals that the mouse cursor has moved on or off a URL.
  615.      *
  616.      * @param _url is the URL that the mouse cursor has moved onto.
  617.      * _url is null if the cursor moved off a URL.
  618.      */
  619.     void onURL( const char *_url );
  620.  
  621.     /**
  622.      * Signal that the user has selected text or the existing selection has
  623.      * become unselected.  The text may be retrieved using
  624.      * @ref #getSelectedText.  This is a good signal to connect to for
  625.      * enabling/disabling the Copy menu item or calling XSetSelectionOwner().
  626.      *
  627.      * @param _selected is true if the user has selected text or false if
  628.      * the current selection has been removed.
  629.      */
  630.     void textSelected( bool _selected );
  631.     /**
  632.      * Indicates the document has changed due to new URL loaded
  633.      * or progressive update.  This signal may be emitted several times
  634.      * while the document is being parsed.  It is an ideal opportunity
  635.      * to update any scrollbars.
  636.      */
  637.     void documentChanged();
  638.  
  639.     /**
  640.      * This signal is emitted if the widget got a call to @ref #parse
  641.      * or @ref #begin. This indicates that the widget is working.
  642.      * In a Web Browser you can use this to start an animated logo
  643.      * like netscape does. The signal @ref #documentDone will tell
  644.      * you that the widget finished its job.
  645.      *
  646.      * @see #documentDone
  647.      */
  648.     void documentStarted();
  649.  
  650.     /**
  651.      * This signal is emitted when document is finished parsing
  652.      * and all required images arrived.
  653.      *
  654.      * @see #documentStarted
  655.      */
  656.     void documentDone();
  657.     
  658.     /// Emitted if the user pressed the right mouse button
  659.     /**
  660.      * If the user pressed the right mouse button over a URL than _url
  661.      * points to this URL, otherwise _url will be null.
  662.      * The position is in global coordinates.
  663.      */
  664.     void popupMenu( const char *_url, const QPoint & );
  665.  
  666.     /**
  667.      * This signal is emitted if the user presses the mouse. If he clicks on
  668.      * a link you get the URL in '_url'.
  669.      *
  670.      * @param _url is the clicked URL or null is there was none.
  671.      * @param _target is the target frame if one is mentioned otherwise 0L.
  672.      * @param _ev the @ref QMouseEvent.
  673.      */
  674.     void mousePressed( const char *_url, const char *_target, QMouseEvent *_ev );
  675.   
  676.     // The widget requests to load a file
  677.     /**
  678.      * KHTMLWidget can only load files from your local disk. If it
  679.      * finds a object which requires a remote file, it will emit this
  680.      * signal. If the file is loaded at some time, call @ref #slotFileLoaded.
  681.      *
  682.      * If the file is not needed any more, the signal @ref #cancelFileRequest
  683.      * is emitted.
  684.      *
  685.      * @param _url is the URL of the image that needs to be loaded.
  686.      */
  687.     void fileRequest( const char *_url );
  688.     
  689.     // Cancels a file that has been requested.
  690.     void cancelFileRequest( const char *_url );
  691.  
  692.     // signal when user has submitted a form
  693.     void formSubmitted( const char *_method, const char *_url, const char *_data );
  694.  
  695.     // signal that the HTML Widget has changed size
  696.     void resized( const QSize &size );
  697.          
  698. public slots:
  699.     /**
  700.      * Scrolls the document to _y.
  701.      *
  702.      * This is usually connected to a scrollbar.
  703.      */
  704.     void slotScrollVert( int _y );
  705.  
  706.     /**
  707.      * Scrolls the document to _x.
  708.      *
  709.      * This is usually connected to a scrollbar.
  710.      */
  711.     void slotScrollHorz( int _x );
  712.  
  713.     /**
  714.      * Call when a file requested by @ref #fileRequest has been loaded.
  715.      *
  716.      * @param _url is the URL of the file that was requested.
  717.      * @param _filename is the name of the file that has been stored on
  718.      * the local filesystem.
  719.      */
  720.     void slotFileLoaded( const char *_url, const char *_filename );
  721.   
  722. protected slots:
  723. //    void slotTimeout();
  724.  
  725.     /*
  726.      * INTERNAL
  727.      *
  728.      * Called when the widget needs an update.
  729.      */
  730.     void slotUpdate();
  731.  
  732.     /*
  733.      * INTERNAL
  734.      *
  735.      * Called by timer event when the widget is due to autoscroll.
  736.      */
  737.     void slotAutoScrollY();
  738.  
  739.     /*
  740.      * INTERNAL
  741.      *
  742.      * Used to update the selection when the user has caused autoscrolling
  743.      * by dragging the mouse out of the widget bounds.
  744.      */
  745.     void slotUpdateSelectText( int newy );
  746.  
  747.     /*
  748.      * INTERNAL
  749.      *
  750.      * Called when the user submitted a form.
  751.      */
  752.     void slotFormSubmitted( const char *_method, const char *_url, const char *_data );
  753.  
  754.     /*
  755.      * INTERNAL
  756.      *
  757.      * Called if this widget displays a frameset and the user selected
  758.      * one of the frames. In this case we have to unselect the
  759.      * currently selected frame if there is one.
  760.      */
  761.     void slotFrameSelected( KHTMLView *_view );
  762.   
  763. public:
  764.     enum ListNumType { Numeric = 0, LowAlpha, UpAlpha, LowRoman, UpRoman };
  765.     enum ListType { Unordered, UnorderedPlain, Ordered, Menu, Dir };
  766.  
  767. protected:
  768.     virtual void mousePressEvent( QMouseEvent * );
  769.  
  770.     /**
  771.      * This function emits the 'doubleClick' signal when the user
  772.      * double clicks a <a href=...> tag.
  773.      */
  774.     virtual void mouseDoubleClickEvent( QMouseEvent * );
  775.  
  776.     /**
  777.      * Overload this method if you dont want any drag actions.
  778.      */
  779.     virtual void dndMouseMoveEvent( QMouseEvent * _mouse );
  780.  
  781.     /**
  782.      * This function emits the 'URLSelected' signal when the user
  783.      * pressed a <a href=...> tag.
  784.      */
  785.     virtual void dndMouseReleaseEvent( QMouseEvent * );
  786.  
  787.     virtual void dragEndEvent();
  788.  
  789.     /**
  790.      * Called when a URL is encountered.  Overload this method to indicate
  791.      * which links have been visited previously.
  792.      *
  793.      * @return true if the URL has been visited previously.  If true is
  794.      * returned the URL will be rendered in the vlink color.  If false
  795.      * is returned the URL will be rendered in the link color.
  796.      */
  797.     virtual bool URLVisited( const char *_url );
  798.  
  799.     virtual void paintEvent( QPaintEvent * );
  800.  
  801.     virtual void resizeEvent( QResizeEvent * );
  802.  
  803.     virtual void keyPressEvent( QKeyEvent * );
  804.  
  805.     virtual void timerEvent( QTimerEvent * );
  806.  
  807.     // we don't want global palette changes affecting us
  808.     virtual void setPalette( const QPalette & ) {}
  809.  
  810.     // reimplemented to prevent flicker
  811.     virtual void focusInEvent( QFocusEvent * ) { }
  812.     virtual void focusOutEvent( QFocusEvent * ) { }
  813.  
  814.     // flush key presses from the event queue
  815.     void flushKeys();
  816.  
  817.     // do </a> if necessary
  818.     void closeAnchor()
  819.     {
  820.     if ( url )
  821.     {
  822.         popColor();
  823.         popFont();
  824.     }
  825.     url = 0;
  826.     target = 0;
  827.     }
  828.  
  829.     /*
  830.      * This function is called after <body> usually. You can
  831.      * call it for every rectangular area: For example a tables cell
  832.      * or for a menus <li> tag. ht gives you one token after another.
  833.      * _clue points to a VBox. All HTMLObjects created by this
  834.      * function become direct or indirect children of _clue.
  835.      * The last two parameters define which token signals the end
  836.      * of the section this function should parse, for example </body>.
  837.      * You can specify two tokens, for example </li> and </menu>.
  838.      * You may even set the second one to "" if you dont need it.
  839.      */
  840.     const char* parseBody( HTMLClueV *_clue, const char *[], bool toplevel = FALSE );
  841.  
  842.     const char* parseOneToken( HTMLClueV *_clue, const char *str );
  843.  
  844.     /*
  845.      * Parse marks starting with character, e.g.
  846.      * <img ...  is processed by KHTMLWidget::parseI()
  847.      * </ul>     is processed by KHTMLWidget::parseU()
  848.      */
  849.     void parseA( HTMLClueV *_clue, const char *str );
  850.     void parseB( HTMLClueV *_clue, const char *str );
  851.     void parseC( HTMLClueV *_clue, const char *str );
  852.     void parseD( HTMLClueV *_clue, const char *str );
  853.     void parseE( HTMLClueV *_clue, const char *str );
  854.     void parseF( HTMLClueV *_clue, const char *str );
  855.     void parseG( HTMLClueV *_clue, const char *str );
  856.     void parseH( HTMLClueV *_clue, const char *str );
  857.     void parseI( HTMLClueV *_clue, const char *str );
  858.     void parseJ( HTMLClueV *_clue, const char *str );
  859.     void parseK( HTMLClueV *_clue, const char *str );
  860.     void parseL( HTMLClueV *_clue, const char *str );
  861.     void parseM( HTMLClueV *_clue, const char *str );
  862.     void parseN( HTMLClueV *_clue, const char *str );
  863.     void parseO( HTMLClueV *_clue, const char *str );
  864.     void parseP( HTMLClueV *_clue, const char *str );
  865.     void parseQ( HTMLClueV *_clue, const char *str );
  866.     void parseR( HTMLClueV *_clue, const char *str );
  867.     void parseS( HTMLClueV *_clue, const char *str );
  868.     void parseT( HTMLClueV *_clue, const char *str );
  869.     void parseU( HTMLClueV *_clue, const char *str );
  870.     void parseV( HTMLClueV *_clue, const char *str );
  871.     void parseW( HTMLClueV *_clue, const char *str );
  872.     void parseX( HTMLClueV *_clue, const char *str );
  873.     void parseY( HTMLClueV *_clue, const char *str );
  874.     void parseZ( HTMLClueV *_clue, const char *str );
  875.  
  876.     /*
  877.      * This function is called after the <cell> tag.
  878.      */
  879.     const char* parseCell( HTMLClue *_clue, const char *attr );
  880.  
  881.     /*
  882.      * parse table
  883.      */
  884.     const char* parseTable( HTMLClue *_clue, int _max_width, const char * );
  885.  
  886.     /*
  887.      * parse input
  888.      */
  889.     const char* parseInput( const char * );
  890.  
  891.     /*
  892.      * This function is used for convenience only. It inserts a vertical space
  893.      * if this has not already been done. For example
  894.      * <h1>Hello</h1><p>How are you ?
  895.      * would insert a VSpace behind </h1> and one in front of <p>. This is one
  896.      * VSpace too much. So we use 'space_inserted' to avoid this. Look at
  897.      * 'parseBody' to see how to use this function.
  898.      * Assign the return value to 'space_inserted'.
  899.      */
  900.     bool insertVSpace( HTMLClueV *_clue, bool _space_inserted );
  901.  
  902.     /*
  903.      * draw background area
  904.      */
  905.     void drawBackground( int _xval, int _yval, int _x, int _y, int _w, int _h );
  906.  
  907.     /*
  908.      * position form elements (widgets) on the page
  909.      */
  910.     void positionFormElements();
  911.  
  912.     /*
  913.      * The <title>...</title>.
  914.      */
  915.     QString title;
  916.  
  917.     /*
  918.      * If we are in an <a href=..> ... </a> tag then the href
  919.      * is stored in this string.
  920.      */
  921.     char *url;
  922.  
  923.     /*
  924.      * If we are in an <a target=..> ... </a> tag then this points to the
  925.      * target.
  926.      */
  927.     char *target;
  928.  
  929.     /*
  930.      * This is the URL that the cursor is currently over
  931.      */
  932.     QString overURL;
  933.  
  934.     /*
  935.      * This painter is created at need, for example to draw
  936.      * a selection or for font metrics stuff.
  937.      */
  938.     QPainter *painter;
  939.  
  940.     /*
  941.      * This is the pointer to the tree of HTMLObjects.
  942.      */
  943.     HTMLClueV *clue;
  944.  
  945.     /*
  946.      * This is the scroll offset. The upper left corner is (0,0).
  947.      */
  948.     int x_offset, y_offset;
  949.  
  950.     /*
  951.      * The amount to auto scroll by.
  952.      */
  953.     int autoScrollDY;
  954.  
  955.     /*
  956.      * The delay to wait before auto scrolling autoScrollDY
  957.      */
  958.     int autoScrollYDelay;
  959.  
  960.     /*
  961.      * Timer for autoscroll stuff
  962.      */
  963.     QTimer autoScrollYTimer;
  964.  
  965.     /*
  966.      * Timer used to schedule paint events
  967.      */
  968.     QTimer updateTimer;
  969.  
  970.     /*
  971.      * This object contains the complete text. This text is referenced
  972.      * by HTMLText objects for example. So you may not delete
  973.      * 'ht' until you have delete the complete tree 'clue' is
  974.      * pointing to.
  975.      */
  976.     HTMLTokenizer *ht;
  977.  
  978.     /*
  979.      * This is used generally for processing the contents of < ... >
  980.      * We keep a class global instance of this object to reduce the
  981.      * number of new/deletes performed.  If your function may be
  982.      * called recursively, or somehow from a function using this
  983.      * tokenizer, you should construct your own.
  984.      */
  985.     StringTokenizer *stringTok;
  986.  
  987.     /*
  988.      * Selects a new font adding _relative_font_size to fontBase
  989.      * to get the new size.
  990.      */
  991.     void selectFont( int _relative_font_size );
  992.  
  993.     /*
  994.      * Selects a new font using current settings
  995.      */
  996.     void selectFont();
  997.  
  998.     /*
  999.      * Makes the font specified by parameters the actual font
  1000.      */
  1001.     void selectFont( const char *_fontfamily, int _size, int _weight, bool _italic );
  1002.  
  1003.     /*
  1004.      * Pops the top font form the stack and makes the new
  1005.      * top font the actual one. If the stack is empty ( should never
  1006.      * happen! ) the default font is pushed on the stack.
  1007.      */
  1008.     void popFont();
  1009.  
  1010.     const HTMLFont *currentFont()  { return font_stack.top(); }
  1011.  
  1012.     void popColor();
  1013.  
  1014.     // List of all objects waiting to get a remote file loaded
  1015.     QList<HTMLObject> waitingFileList;
  1016.     
  1017.     /*
  1018.      * The font stack. The font on top of the stack is the currently
  1019.      * used font. Poping a font from the stack deletes the font.
  1020.      * So use top() to get the actual font. There must always be at least
  1021.      * one font on the stack.
  1022.      */
  1023.     QStack<HTMLFont> font_stack;
  1024.  
  1025.     /*
  1026.      * The weight currently selected. This is affected by <b>..</b>
  1027.      * for example.
  1028.      */
  1029.     int weight;
  1030.  
  1031.     /*
  1032.      * The fonts italic flag. This is affected by <i>..</i>
  1033.      * for example.
  1034.      */
  1035.     bool italic;
  1036.  
  1037.     /*
  1038.      * The fonts underline flag. This is affected by <u>..</u>
  1039.      * for example.
  1040.      */
  1041.     bool underline;
  1042.  
  1043.     /*
  1044.      * The fonts underline flag. This is affected by <u>..</u>
  1045.      * for example.
  1046.      */
  1047.     bool strikeOut;
  1048.  
  1049.     /*
  1050.      * Used for drag and drop.
  1051.      */
  1052.     bool pressed;
  1053.     int press_x, press_y;
  1054.     /*
  1055.      * When the user presses the mouse over an URL, this URL is stored
  1056.      * here. We might need it if the user just started a drag.
  1057.      */
  1058.     QString pressedURL;
  1059.  
  1060.     /**
  1061.      * If the user pressed the mouse button over an URL then this is the name
  1062.      * of the target window for this hyper link. Used to implement frames.
  1063.      *
  1064.      * @see #pressedURL
  1065.      */
  1066.     QString pressedTarget;
  1067.  
  1068.     /*
  1069.      * If the user drags a URL out of the widget, by default this pixmap
  1070.      * is used for the dragged icon. The pixmap is loaded in the constructor.
  1071.      */
  1072.     QPixmap dndDefaultPixmap;
  1073.  
  1074.     /*
  1075.      * Start of selection
  1076.      */
  1077.     QPoint selectPt1;
  1078.  
  1079.     /*
  1080.      * End of selection
  1081.      */
  1082.     QPoint selectPt2;
  1083.  
  1084.     /*
  1085.      * is any text currently selected
  1086.      */
  1087.     bool bIsTextSelected;
  1088.  
  1089.     /*
  1090.      * This is the URL which is visible on the screen. This URL
  1091.      * is needed to complete URLs like <a href="classes.html"> since
  1092.      * for example 'URLSelected' should provide a complete URL.
  1093.      */
  1094.     KURL actualURL;
  1095.     KURL baseURL;    // this will do for now - MRJ
  1096.             // actually we need something like this to implement
  1097.             // <base ...>
  1098.  
  1099.     /*
  1100.      * from <BASE TARGET="...">
  1101.      */
  1102.     QString baseTarget;
  1103.  
  1104.     /*
  1105.      * Current text color is at the top of the stack
  1106.      */
  1107.     QStack<QColor> colorStack;
  1108.  
  1109.     /*
  1110.      * A color context for the current page so that we can free the colors
  1111.      * when we close the page.
  1112.      */
  1113.     int colorContext;
  1114.  
  1115.     /*
  1116.      * Timer to parse html in background
  1117.      */
  1118.     int timerId;
  1119.  
  1120.     /*
  1121.      * begin() has been called, but not end()
  1122.      */
  1123.     bool writing;
  1124.  
  1125.     /*
  1126.      * Is the widget currently parsing
  1127.      */
  1128.     bool parsing;
  1129.  
  1130.     /*
  1131.      * Have we parsed <body> yet?
  1132.      */
  1133.     bool bodyParsed;
  1134.  
  1135.     /*
  1136.      * size of current indenting
  1137.      */
  1138.     int indent;
  1139.  
  1140.     class HTMLList
  1141.     {
  1142.     public:
  1143.         HTMLList( ListType t, ListNumType nt = Numeric )
  1144.         { type = t; numType = nt; itemNumber = 1; }
  1145.         ListType type;
  1146.         ListNumType numType;
  1147.         int itemNumber;
  1148.     };
  1149.  
  1150.     /*
  1151.      * Stack of lists currently active.
  1152.      * The top affects whether a bullet or numbering is used by <li>
  1153.      */
  1154.     QStack<HTMLList> listStack;
  1155.  
  1156.     enum GlossaryEntry { GlossaryDL, GlossaryDD };
  1157.  
  1158.     /*
  1159.      * Stack of glossary entries currently active
  1160.      */
  1161.     QStack<GlossaryEntry> glossaryStack;
  1162.  
  1163.     /*
  1164.      * The current alignment, set by <DIV > or <CENTER>
  1165.      */
  1166.     HTMLClue::HAlign divAlign;
  1167.  
  1168.     /*
  1169.      * Number of tokens parsed in the current time-slice
  1170.      */
  1171.     int parseCount;
  1172.     int granularity;
  1173.  
  1174.     /*
  1175.      * Used to avoid inserting multiple vspaces
  1176.      */
  1177.     bool vspace_inserted;
  1178.  
  1179.     /*
  1180.      * The current flow box to add objects to
  1181.      */
  1182.     HTMLClue *flow;
  1183.  
  1184.     /*
  1185.      * Array of paser functions, e.g.
  1186.      * <img ...  is processed by KHTMLWidget::parseI() - parseFuncArray[8]()
  1187.      * </ul>     is processed by KHTMLWidget::parseU() - parseFuncArray[20]()
  1188.      */
  1189.     static parseFunc parseFuncArray[26];
  1190.  
  1191.     /*
  1192.      * This list holds strings which are displayed in the view,
  1193.      * but are not actually contained in the HTML source.
  1194.      * e.g. The numbers in an ordered list.
  1195.      */
  1196.     QStrList tempStrings;
  1197.  
  1198.     /*
  1199.      * This list holds all <a href= urls in the document.
  1200.      */
  1201.     QStrList parsedURLs;
  1202.     QStrList parsedTargets;
  1203.  
  1204.     QPixmap bgPixmap;
  1205.  
  1206.     /*
  1207.      * This is the cusor to use when over a link
  1208.      */
  1209.     QCursor linkCursor;
  1210.  
  1211.     /*
  1212.      * Current fontbase, colors, etc.
  1213.      */
  1214.     HTMLSettings *settings;
  1215.  
  1216.     /*
  1217.      * Default settings.
  1218.      */
  1219.     HTMLSettings *defaultSettings;
  1220.  
  1221.     // should the background be painted?
  1222.     bool bDrawBackground;
  1223.  
  1224.     /*
  1225.      * The URL of the not loaded!! background image
  1226.      * If we are waiting for a background image then this is its URL.
  1227.      * If the image is already loaded or if we don't have one this variable
  1228.      * contains 0. You can write bgPixmapURL.isNull() to test wether we are
  1229.      * waiting for a background pixmap.
  1230.      */
  1231.     QString bgPixmapURL;
  1232.  
  1233.     // true if the current text is destined for <title>
  1234.     bool inTitle;
  1235.  
  1236.     // List of forms in the page
  1237.     QList<HTMLForm> formList;
  1238.  
  1239.     // Current form
  1240.     HTMLForm *form;
  1241.  
  1242.     // Current select form element
  1243.     HTMLSelect *formSelect;
  1244.  
  1245.     // true if the current text is destined for a <SELECT><OPTION>
  1246.     bool inOption;
  1247.  
  1248.     // Current textarea form element
  1249.     HTMLTextArea *formTextArea;
  1250.  
  1251.     // true if the current text is destined for a <TEXTAREA>...</TEXTAREA>
  1252.     bool inTextArea;
  1253.  
  1254.     // the text to be put in a form element
  1255.     QString formText;
  1256.  
  1257.     /*
  1258.      * Image maps used in this document
  1259.      */
  1260.     QList<HTMLMap> mapList;
  1261.  
  1262.     /*
  1263.      * The toplevel frame set if we have frames otherwise 0L.
  1264.      */
  1265.     HTMLFrameSet *frameSet;
  1266.  
  1267.     /*
  1268.      * Stack of framesets used during parsing.
  1269.      */
  1270.     QList<HTMLFrameSet> framesetStack;
  1271.  
  1272.     /*
  1273.      * List of all framesets we are currently showing.
  1274.      * This list is not cleared after parsing like @ref #framesetStack.
  1275.      */
  1276.     QList<HTMLFrameSet> framesetList;  
  1277.  
  1278.     /*
  1279.      * List of all frames appearing in this window. They are stored in
  1280.      * source order. JavaScript uses this list to implement its
  1281.      * frames array.
  1282.      */
  1283.     QList<KHTMLWidget> frameList;    
  1284.  
  1285.     /*
  1286.      * @return TRUE if the current document is a framed document.
  1287.      */
  1288.     bool bIsFrameSet;
  1289.  
  1290.     /*
  1291.      * @return TRUE if the widget is a frame of a frameset.
  1292.      */
  1293.     bool bIsFrame;
  1294.  
  1295.     /*
  1296.      * Is TRUE if we parsed the complete frame set.
  1297.      */
  1298.     bool bFramesComplete;
  1299.  
  1300.     /*
  1301.      * If the owner of this widget is a @ref HTMLView then this is a
  1302.      * pointert to the owner, otherwise 0L.
  1303.      */
  1304.     KHTMLView *htmlView;
  1305.  
  1306.     /*
  1307.      * This is a pointer to the selectede frame. This means that the frame
  1308.      * gets a black inner border.
  1309.      */
  1310.     KHTMLView *selectedFrame;
  1311.  
  1312.     /*
  1313.      * Flag that indicates wether the user selected this widget. This is only of
  1314.      * interest if the widget is a frame in a frameset. Try Netscape to see
  1315.      * what I mean.
  1316.      *
  1317.      * @see #selectedFrame
  1318.      */
  1319.     bool bIsSelected;
  1320.  
  1321.     /*
  1322.      * Holds the amount of pixel for the left border. This variable is used
  1323.      * to implement the
  1324.      * <tt><frame marginwidth=... ></tt> tag.
  1325.      *
  1326.      * @see #rightBorder
  1327.      * @see #setMarginWidth
  1328.      */
  1329.     int leftBorder;
  1330.  
  1331.     /*
  1332.      * Holds the amount of pixel for the right border. This variable is used
  1333.      * to implement the
  1334.      * <tt><frame marginwidth=... ></tt> tag.
  1335.      *
  1336.      * @see #leftBorder
  1337.      * @see #setMarginWidth
  1338.      */
  1339.     int rightBorder;
  1340.  
  1341.     /*
  1342.      * Holds the amount of pixel for the top border. This variable is used
  1343.      * to implement the
  1344.      * <tt><frame marginheight=... ></tt> tag.
  1345.      *
  1346.      * @see #bottomBorder
  1347.      * @see #setMarginHeight
  1348.      */
  1349.     int topBorder;
  1350.  
  1351.     /*
  1352.      * Holds the amount of pixel for the bottom border. This variable is used
  1353.      * to implement the
  1354.      * <tt><frame marginheight=... ></tt> tag.
  1355.      *
  1356.      * @see #setMarginHeight
  1357.      * @see #topBorder
  1358.      */
  1359.     int bottomBorder;
  1360.  
  1361.     /*
  1362.      * This pointer is per default 0L. An instance of @ref JSEnvironment is
  1363.      * created if someone calls @ref #getJSEnvironment. This instance is used
  1364.      * to run java script.
  1365.      */
  1366.     JSEnvironment *jsEnvironment;      
  1367.     KCharsetConverter *charsetConverter;
  1368. };
  1369.  
  1370. #endif // HTML
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.